#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void Swap(char* buf1, char* buf2, int width) {
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;
		buf1++;
		buf2++;
	}
}
int cmp(const void* elem1, const void* elem2)
{
	return *(int*)elem1 - *(int*)elem2;
}
void bubble_sort(void* base, size_t num, size_t width,
	int(*compare)(const void* elem1, const void* elem2))
{
	int i,j = 0;
	for (i = 0; i < num - 1; i++)
	{
		for (j = 0; j < num - 1 - i; j++)
		{
			if (compare((char*)base+j*width,(char*)base + (j+1) * width)>0 )
			{
				Swap((char*)base+j*width,(char*)base+ (j + 1) * width,width);
			}
		}
	}


}
int main()
{
	int arr[] = {7,2,4,1,4,5,6};
	int len = sizeof(arr) / sizeof(arr[0]);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	bubble_sort(arr, len, sizeof(arr[0]), cmp);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}
